package com.api.shopapi.service.impl;


import com.api.shopapi.entity.Staff;
import com.api.shopapi.entity.dto.StaffDTO;
import com.api.shopapi.mapper.StaffMapper;
import com.api.shopapi.service.StaffService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;


@Repository
@Service("StaffServiceImplOne")
public class StaffServiceImpl implements StaffService {

    @Autowired
    private StaffMapper staffMapper;



    @Override
    public int insert(Staff staff){
        return staffMapper.insert(staff);
    }

    @Override
    public int deleteByStaffCode(String staffCode){
        return staffMapper.deleteByStaffCode(staffCode);
    }

    @Override
    public int updateByStaffCode(Staff staff){
        return staffMapper.updateByStaffCode(staff);
    }

    @Override
    public Staff getByStaffCode(String staffCode){
        return staffMapper.getByStaffCode(staffCode);
    }

    @Override
    public Staff getByLoginName(String loginName){
        return staffMapper.getByLoginName(loginName);
    }

    @Override
    public Staff getByPhone(String phone){
        return staffMapper.getByPhone(phone);
    }

    @Override
    public Staff getByLoginNamePassword(String loginName,String password){
        return staffMapper.getByLoginNamePassword(loginName,password);
    }


    @Override
    public Staff getByRoleNameGovernmentCode(String roleName,String governmentCode){
        return staffMapper.getByRoleNameGovernmentCode(roleName,governmentCode);
    }


    @Override
    public List<Staff> getList() {
        return staffMapper.getList();
    }

    @Override
    public List<StaffDTO> getListStaffDTO(){
        return staffMapper.getListStaffDTO();
    }

    @Override
    public List<Staff> getListByRoleNameGovernmentCode(String roleName,String governmentCode){
        return staffMapper.getListByRoleNameGovernmentCode(roleName,governmentCode);
    }

    @Override
    public PageInfo<Staff> getPageInfo(int pageIndex, int pageSize){
        PageHelper.startPage(pageIndex, pageSize);
        List<Staff> listStaff = staffMapper.getList();
        PageInfo<Staff> pageInfo = new PageInfo<Staff>(listStaff);
        return pageInfo;
    }

    @Override
    public PageInfo<StaffDTO> getPageInfoStaffDTO(int pageIndex, int pageSize){
        PageHelper.startPage(pageIndex, pageSize);
        List<StaffDTO> listStaffDTO = staffMapper.getListStaffDTO();
        PageInfo<StaffDTO> pageInfoDTO = new PageInfo<StaffDTO>(listStaffDTO);
        return pageInfoDTO;
    }

    @Override
    public List<StaffDTO> getListStaffDTOByGovernmentCode(String governmentCode) {
        return staffMapper.getListStaffDTOByGovernmentCode(governmentCode);
    }

    @Override
    public PageInfo<StaffDTO> getPageInfoStaffDTOByGovernmentCode(int pageIndex, int pageSize,String governmentCode){
        PageHelper.startPage(pageIndex, pageSize);
        List<StaffDTO> listStaffDTO = staffMapper.getListStaffDTOByGovernmentCode(governmentCode);
        PageInfo<StaffDTO> pageInfoDTO = new PageInfo<StaffDTO>(listStaffDTO);
        return pageInfoDTO;
    }

    @Override
    public List<StaffDTO> getListStaffByGovernmentCode(String governmentCode) {
        return staffMapper.getListStaffByGovernmentCode(governmentCode);
    }


    //模糊查询职工
    @Override
    public PageInfo<StaffDTO> getListForSelect(int pageIndex, int pageSize, String governmentCode, String realName, String phone) {
        PageHelper.startPage(pageIndex,pageSize);
        List<StaffDTO> staffDTOList =staffMapper.getListForSelect(governmentCode, realName, phone);
        return new PageInfo<>(staffDTOList);
    }

    @Override
    public PageInfo<StaffDTO> getListForBusiness111(int pageIndex, int pageSize, String governmentCode, String realName, String phone) {
        PageHelper.startPage(pageIndex,pageSize);
        List<StaffDTO> staffDTOList =staffMapper.getListForBusiness111(governmentCode, realName, phone);
        return new PageInfo<>(staffDTOList);
    }


    @Override
    public PageInfo<StaffDTO> getListForBusiness222(int pageIndex, int pageSize, String governmentCode, String realName, String phone) {
        PageHelper.startPage(pageIndex,pageSize);
        List<StaffDTO> staffDTOList =staffMapper.getListForBusiness222(governmentCode, realName, phone);
        return new PageInfo<>(staffDTOList);
    }

    @Override
    public PageInfo<StaffDTO> getListForBusiness(int pageIndex, int pageSize, String governmentCode, String realName, String phone, String parentStaffCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<StaffDTO> staffDTOList =staffMapper.getListForBusiness(governmentCode, realName, phone, parentStaffCode);
        return new PageInfo<>(staffDTOList);
    }

    @Override
    public PageInfo<Staff> getListStaffForAdmin(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Staff> staffList=staffMapper.getListStaffForAdmin();
        return new PageInfo<>(staffList);
    }

    @Override
    public PageInfo<StaffDTO> getListStaffForGovAdmin(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<StaffDTO> staffList=staffMapper.getListStaffForGovAdmin();
        return new PageInfo<>(staffList);
    }

    @Override
    public PageInfo<StaffDTO> getListStaffForSeats(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<StaffDTO> staffList=staffMapper.getListStaffForSeats();
        return new PageInfo<>(staffList);
    }

    @Override
    public List<StaffDTO> getUnboundForSeats(String governmentCode,String staffCode) {
        List<StaffDTO> staffList=staffMapper.getUnboundForSeats(governmentCode,staffCode);
        return staffList;
    }

    @Override
    public List<StaffDTO> getByBusinessCode(String businessCode) {
        return staffMapper.getByBusinessCode(businessCode);
    }


    @Override
    public List<Staff> getByGovernmentCodeAndRoleCode(String roleName, String roleCode){
        return staffMapper.getByGovernmentCodeAndRoleCode(roleName,roleCode);
    }

    /**
     * 查询政府内某一类型的所有职工
     * */
    @Override
    public
    PageInfo<Staff> pageByGovCodeRoleName(int pageIndex, int pageSize, String governmentCode,String roleName, String realName, String phone){
        PageHelper.startPage(pageIndex,pageSize);
        List<Staff> list=staffMapper.listByGovCodeRoleName(governmentCode,roleName,realName,phone);
        return new PageInfo<>(list);
    }


    /**
     * 查询机构内某一类型的所有职工
     * */
    @Override
    public
    PageInfo<Staff> pageByInsCodeRoleName(int pageIndex, int pageSize, String institutionCode,String roleName, String realName, String phone){
        PageHelper.startPage(pageIndex,pageSize);
        List<Staff> list=staffMapper.listByInsCodeRoleName(institutionCode,roleName,realName,phone);
        return new PageInfo<>(list);
    }

    @Override
    public List<Staff> query(String realName) {
        return staffMapper.query(realName);
    }


}